package com.kedou.sdk.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;


public class ExViewPager extends ViewPager {

    private boolean gestureSlideEnable;

    public ExViewPager(Context context) {
        super(context);
        this.gestureSlideEnable = false;
    }

    public ExViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.gestureSlideEnable = false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return this.gestureSlideEnable && super.onTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return this.gestureSlideEnable && super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean executeKeyEvent(@NonNull KeyEvent event) {
        return this.gestureSlideEnable && super.executeKeyEvent(event);
    }

    public boolean isGestureSlideEnable() {
        return gestureSlideEnable;
    }

    public void setGestureSlideEnable(boolean gestureSlideEnable) {
        this.gestureSlideEnable = gestureSlideEnable;
    }

//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        int height = 0;
//        //下面遍历所有child的高度
//        for (int i = 0; i < getChildCount(); i++) {
//            View child = getChildAt(i);
//            child.measure(widthMeasureSpec,
//                    MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
//            int h = child.getMeasuredHeight();
//            if (h > height) //采用最大的view的高度。
//                height = h;
//        }
//        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,
//                MeasureSpec.EXACTLY);
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//
//    }
}
